package com.aatrox.bhsypro.service.impl;

import com.aatrox.bhsypro.dao.BUserDao;
import com.aatrox.bhsypro.entity.AliBean;
import com.aatrox.bhsypro.pay.AliPay;
import com.aatrox.bhsypro.service.PayService;
import com.alipay.api.AlipayApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PayServiceImpl implements PayService {

    @Autowired
    private AliPay aliPay;

    @Autowired
    private BUserDao ud;

    @Override
    public String aliPay(AliBean alipayBean) throws AlipayApiException {
        System.out.println(alipayBean.toString());
        if (alipayBean.getOut_trade_no().startsWith("huiyua")){
            int uid = Integer.parseInt(alipayBean.getOut_trade_no().substring(6,alipayBean.getOut_trade_no().indexOf("Y")));
            System.out.println("{}"+uid);
            ud.updateUserVip(uid);
        }
        return aliPay.pay(alipayBean);
    }
}
